
#ifndef _IHTMLSTYLE_H_
#define _IHTMLSTYLE_H_

#include <BMap>
#include <BColor>
#include <BIcon>
#include <BImage>
#include <BFont>
#include <BWidget>
#include <BHtmlItem>

namespace BWE
{
	class IHtmlStyle : public BObject
	{
	public:
		IHtmlStyle();
		IHtmlStyle(const BString& name);
		~IHtmlStyle();

		template<class T>
		bool assign(const char* name, T& obj)
		{
			auto it = valueMap.find(name);
			if (it.empty())
				return false;
			if (!it->is<T>())
				return false;
			obj = *it;
			return true;
		}

		bool apply(BHtmlItem* item) const;
		void overlap(const IHtmlStyle* style);

		void setValue(const BString& name, const BValue& value);
		bool removeVlaue(const BString& name);
		const BValue& value(const BString& name) const;

		bool clearValues();

	public:
		bool addSub(IHtmlStyle* style);
		bool removeSub(IHtmlStyle* style);
		bool clearSubs();

		int annexCount() const;
		IHtmlStyle* annex(int index);
		const IHtmlStyle* annex(int index) const;

		IHtmlStyle* annex(const BString& name);
		const IHtmlStyle* annex(const BString& name) const;

		IHtmlStyle* annex(const char* name);
		const IHtmlStyle* annex(const char* name) const;

	public:
		bool addChild(IHtmlStyle* child);
		IHtmlStyle* addChild(const BString& name);
		bool removeChild(IHtmlStyle* child);
		bool clearChildren();

		int childCount() const;
		IHtmlStyle* child(int index);
		const IHtmlStyle* child(int index) const;

		IHtmlStyle* child(const BString& name);
		const IHtmlStyle* child(const BString& name) const;

		IHtmlStyle* child(const BString& name, const BString& id, const BString& cls);

	public:
		IHtmlStyle*			parent;
		BString				id;
		BString				cls;

		BMap<BString, BValue>			valueMap;
		BArray<BHolder<IHtmlStyle>>		annexes;
		BArray<BHolder<IHtmlStyle>>		children;
	};
}

#endif
